<%--
  Created by IntelliJ IDEA.
  User: Adminis
  Date: 2025/3/19
  Time: 11:24
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="com.ws.lv.util.Res" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/admin/css/bootstrap.min.css">
    <script src="${pageContext.request.contextPath}/admin/js/jquery-2.1.0.min.js"></script>
    <script src="${pageContext.request.contextPath}/admin/js/bootstrap.min.js"></script>
    <style>

        .cus-container {
            width: 1368px;
        }

        #user-add .modal-content {
            padding: 0 20px 20px;
        }

        #user-edit .modal-content {
            padding: 0 20px 20px;
        }
        .tx{
            width: 60px;
            height: 60px;
            border-radius: 50%;
        }
        b{
            color: red;
        }

    </style>
</head>
<body>

<div class="container cus-container">
    <h3 class="text-center">用户信息列表</h3>

    <div>
        <!-- 搜索框div -->
        <div id="search-user" style="float: left; margin: 10px 0px;">
            <form class="form-inline" action="${pageContext.request.contextPath}/acl_user/selectAcl_users" method="post">
                <div class="form-group">
                    <label for="username">用户名</label>
                    <input type="text" name="username" value="${username}" class="form-control" id="username">
                </div>
                &nbsp;&nbsp;&nbsp;
				<div class="form-group">
					<label for="is_deleted">是否删除</label>
					<select class="form-control" name="is_deleted" id="is_deleted">
						<option value=""> -请选择是否删除- </option>
						<option value="1" ${is_deleted == "1" ? "selected" : ""}>是</option>
						<option value="0" ${is_deleted == "0" ? "selected" : ""}>否</option>
					</select>
                </div>
                &nbsp;&nbsp;&nbsp;
				<div class="form-group">
					<label for="sid">所属商家</label>
					<select class="form-control" name="sid" id="sid">
						<option value=""> -请选择所属商家- </option>
                        <c:forEach items="${suppliers}" var="supplier">
							<option value="${supplier.supplier_id}" ${sid == supplier.supplier_id ? "selected" : ""}>${supplier.supplier_name}</option>
						</c:forEach>
					</select>
                </div>
                &nbsp;&nbsp;&nbsp;
                <button type="submit" class="btn btn-default">查询</button>
            </form>
        </div>

        <!-- 添加、删除的按钮 -->
        <div style="float: right;margin: 10px 0px;">
            <a class="btn btn-primary" href="${pageContext.request.contextPath}/acl_user/toInsertAcl_user">添加用户</a>
            <a class="btn btn-primary" onclick="dels()">删除选中</a>
        </div>
    </div>


    <table class="table table-bordered clearfix" id="user-list">
        <thead>
        <tr class="bg-primary">
            <th><input type="checkbox" id="firstCb"></th>
            <th>用户编号</th>
            <th>用户名</th>
            <th>用户昵称</th>
            <th>用户头像</th>
            <th>是否删除</th>
            <th>所属商家</th>
            <th>创建时间</th>
            <th>更新时间</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${pageInfo.list}" var="acl_user">
            <tr>
                <td><input type="checkbox" class="cb" value="${acl_user.user_id}"></td>
                <td>${acl_user.user_id}</td>
                <td>${acl_user.username}</td>
                <td>${acl_user.nickname}</td>
                <td><img src="<%=Res.adminTxFileUrl%>${acl_user.user_tx}" class="tx" ></td>
                <td>${acl_user.is_deleted == 1 ? "是" : "否"}</td>
                <td>${acl_user.supplier.supplier_name}</td>
                <td><fmt:formatDate value="${acl_user.create_time}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
                <td><fmt:formatDate value="${acl_user.update_time}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
                <td>
                    <a class="btn btn-default btn-sm" href="${pageContext.request.contextPath}/acl_user/softUpdateAcl_user?user_id=${acl_user.user_id}">删除</a>
                    <a class="btn btn-default btn-sm" href="${pageContext.request.contextPath}/acl_user/toUpdateAcl_user?user_id=${acl_user.user_id}">修改</a>
                    <a onclick="czPass(${acl_user.user_id})" class="btn btn-default btn-sm">重置密码</a>
                    <a class="btn btn-default btn-sm" href="${pageContext.request.contextPath}/acl_user/selectAcl_roleAll?user_id=${acl_user.user_id}">分配角色</a>
                </td>
            </tr>
        </c:forEach>

        </tbody>
    </table>

    <%--前五后四--%>

    <c:if test="${pageInfo.pages>=10}">
        <c:set var="begin" value="1"></c:set>
        <c:set var="end" value="10"></c:set>
        <c:if test="${pageInfo.pageNum>5}">
            <c:set var="begin" value="${pageInfo.pageNum-4}"></c:set>
            <c:set var="end" value="${pageInfo.pageNum+5}"></c:set>
        </c:if>
        <c:if test="${pageInfo.pageNum+5>pageInfo.pages}">
            <c:set var="begin" value="${pageInfo.pages-9}"></c:set>
            <c:set var="end" value="${pageInfo.pages}"></c:set>
        </c:if>
    </c:if>

    <c:if test="${pageInfo.pages<10}">
        <c:set var="begin" value="1"></c:set>
        <c:set var="end" value="${pageInfo.pages}"></c:set>
    </c:if>

    <!-- 分页导航 -->
    <div>
        <nav style="text-align: center">
            <ul class="pagination">

                <li>
                    <a href="${pageContext.request.contextPath}/acl_user/selectAcl_users?currentPage=1&username=${username}&is_deleted=${is_deleted}&sid=${sid}">首页</a>
                </li>

                <li>
                    <a href="${pageContext.request.contextPath}/acl_user/selectAcl_users?currentPage=${pageInfo.prePage}&&username=${username}&is_deleted=${is_deleted}&sid=${sid}">&laquo;</a>
                </li>

                <c:forEach begin="${begin}" end="${end}" var="page">
                    <li ${page eq pageInfo.pageNum?"class='active'":''}>
                        <a href="${pageContext.request.contextPath}/acl_user/selectAcl_users?currentPage=${page}&&username=${username}&is_deleted=${is_deleted}&sid=${sid}">${page}</a>
                    </li>
                </c:forEach>

                <li>
                    <a href="${pageContext.request.contextPath}/acl_user/selectAcl_users?currentPage=${pageInfo.nextPage}&&username=${username}&is_deleted=${is_deleted}&sid=${sid}">&raquo;</a>
                </li>

                <li>
                    <a href="${pageContext.request.contextPath}/acl_user/selectAcl_users?currentPage=${pageInfo.pages}&&username=${username}&is_deleted=${is_deleted}&sid=${sid}">尾页</a>
                </li>

            </ul>
        </nav>
        <div style="float: right;">
            <span>当前第<b>${pageInfo.pageNum}</b>页 共<b>${pageInfo.pages}</b>页 共<b>${pageInfo.total}</b>条数据</span>
        </div>
    </div>



</div>
</body>
</html>
<script>
    function dels() {
        let checkeds = $("input[class='cb']:checked");
        let acl_userIds = "";
        for (let i = 0; i < checkeds.length; i++){
            console.log(checkeds[i].value)
            acl_userIds += checkeds[i].value + ",";
        }
        if (acl_userIds.length > 0){
            if (confirm("确定删除吗？")){
                window.location.href = "${pageContext.request.contextPath}/acl_user/deleteAcl_users?user_ids=" + acl_userIds;
            }
        }

    }

    function czPass(user_id) {
        if (confirm("确定重置密码吗?")){
            alert("重置密码成功 密码重置为:123456")
            window.location.href = "${pageContext.request.contextPath}/acl_user/updateAcl_userPassword?user_id=" + user_id;
        }
    }

</script>
